package bulk;

import java.sql.PreparedStatement;
import factory.ConfiguracaoesBD;
import factory.ConnectionFactory;

public class Importacao {

	public void excBulk(String filename) {
		StringBuilder builder = new StringBuilder();
		
		builder.append("BULK INSERT dbo.Clientes ");
		builder.append("   FROM '"+ filename +"' ");
		builder.append("   WITH "); 
		builder.append("      ( ");
		builder.append("         FIELDTERMINATOR ='|', ");
		builder.append("         ROWTERMINATOR ='\\n', ");
		builder.append("         FIRSTROW = 2 ");
		builder.append("      ) ");


		try {
			ConnectionFactory con = null;
			PreparedStatement ps = null;

			con = new ConnectionFactory(ConfiguracaoesBD.LOGIN,
					ConfiguracaoesBD.SENHA, ConfiguracaoesBD.DRIVER,
					ConfiguracaoesBD.URL);
			
			con.conectar();

			ps = con.setStatement(builder.toString());
			ps.execute();

			con.desconectar();

		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.exit(0);
		}
	}

}
